<template>
	<view class="merchant-settlement">
		<view class="subsidiary-settlement-form">
			<view class="subsidiary-settlement-title">
				基础信息
			</view>
			<view class="item-lable">
				<view class="lable-name">姓名</view>
				<view class="lavle-val">
					<input type="text" v-model="form.name" placeholder="请输入姓名" placeholder-style="{'color':'#FAFAFA'}">
				</view>
			</view>
			<view class="item-lable">
				<view class="lable-name">手机号码</view>
				<view class="lavle-val">
					<input type="text" v-model="form.mobile" placeholder="请输入手机号码" placeholder-style="{color:'#FAFAFA'}">
				</view>
			</view>
		</view>
		
		<view class="subsidiary-settlement-form">
			<view class="subsidiary-settlement-title">
				法人实名认证
			</view>
			<view class="card-up-con">
				<view class="item-card" @click="upImage('image','protrait_card')">
					<image :src="sheep.$url.cdn(form.protrait_card)" v-if="form.protrait_card" mode="aspectFill"></image>
					<image v-else src="./static/rxz.png" mode=""></image>
					<view class="item-btn-name">
						<!-- 点击上传身份证原件人像面 -->
					</view>
				</view>
				<view class="item-card" @click="upImage('image','reverse_card')">
					<image :src="sheep.$url.cdn(form.reverse_card)" v-if="form.reverse_card" mode="aspectFill"></image>
					<image src="./static/ghz.png" v-else mode=""></image>
					<view class="item-btn-name">
						<!-- 点击上传身份证原件国徽面 -->
					</view>
				</view>
			</view>
		</view>
		<view class="subsidiary-settlement-form">
			<view class="subsidiary-settlement-title">
				营业执照备案
			</view>
			<view class="item-up-image">
				<image v-if="form.business_license" :src="sheep.$url.cdn(form.business_license)" mode="aspectFill"></image>
				<image v-else @click="upImage('image','business_license')" src="./static/yyzz.png" mode=""></image>
			</view>
		</view>
		
		<view class="delivery-button">
			<button  @click="settlementClick()">提交资料</button>
		</view>
	</view>
</template>

<script setup>
	import sheep from '@/sheep';
	import {chooseFile} from "@/sheep/utils/index.js"
	import App from "@/sheep/api/app.js"
	import { reactive, computed, onBeforeUnmount,nextTick } from 'vue'
	import { onLoad, onShow, onHide } from '@dcloudio/uni-app';
	import merchantApi from '@/sheep/api/merchant'
	import _ from 'lodash'
	const state = reactive({

	})
	const form = reactive({
		name:'',
		mobile:'',
		business_license:'',
		protrait_card:'',
		reverse_card:'',
		serve:1,
		level:1,
		invitecode:'',
	})
	onLoad((opt)=>{
		console.log('opt',opt)
		if(opt.serve){
			form.serve = opt.serve
		}
		if(opt.level){
			form.level = opt.level
		}
		if(opt.invitecode){
			form.invitecode = opt.invitecode
		}
	})
	async function settlementClick(){
		// sheep.$router.go('/pages/supply/examine')
		var title = '';
		if(form.name.length===0){
			title="请填写名字";
		}else if(form.mobile.length===0){
			title="请填写手机号";
		}else if(form.protrait_card.length===0){
			title="请上传身份证正面";
		}else if(form.reverse_card.length==0){
			title="请上传身份证反面";
		}else if(form.business_license.length==0){
			title="请上传营业执照";
		}
		if(title.length>0){
			uni.showToast({
				title:title,
				icon:'none',
				duration: 2000,
			});
			return false;
		}
		const data = await merchantApi.apply({
			...form	
		})
			
			
			uni.showToast({
				title: data.msg,
				icon:'none',
				duration: 2000
			});
			
			
			if(data.error==0){
				_.delay(function(text) {
					uni.switchTab({
						url: '/pages/index/user'
					});
				}, 1000, 'later');
			}
	}
	
	async function  upImage(type,key){
		let file = await chooseFile(type)
		if(file){
			let res = await App.upload(file[0].url)
			if(res){
				form[key] = res.path
			}
			
		}
	}
</script>

<style>
	page{
		background: #FAFAFA;
	}
</style>
<style lang="scss">

	.merchant-settlement {
		padding: 24rpx 24rpx 0;
		.subsidiary-settlement-form{
			width: calc(100% - 48rpx);
			margin: 0 auto;
			margin-bottom: 20rpx;
			background-color: #fff;
			border-radius: 16rpx;
			padding:24rpx 24rpx 0;
			.subsidiary-settlement-title{
				font-size: 32rpx;
				color: #323233;
				// padding-top: 26rpx;
				font-family: Source Han Sans;
				font-weight: bold;
				line-height: 48rpx;
			}
			.card-up-con{
				margin-top: 20rpx;
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.item-card{
					width: calc(50% - 19rpx);
					text-align: center;
					image{
						width: 100%;
						height: 222rpx;
					}
					.item-btn-name{
						padding: 20rpx 0 ;
						font-size: 24rpx;
						color: #666666;
					}
				}
			}
			.item-up-image{
				width: 100%;
				padding-bottom: 24rpx;
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					// width: 128rpx;
					// height: 128rpx;
					width: 620rpx;
					height: 280rpx;
				}
				.up-name{
					margin-left: 16rpx;
					color: #5A76FF;
					font-size: 24rpx;
				}
			}
			.item-lable{
				padding: 30rpx 0;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px solid #F1F1F1;
				.lable-name{
					width: 140rpx;
					font-size: 30rpx;
				}
				.lavle-val{
					display: flex;
					align-items: center;
					input{
						width: 100%;
						text-align: right;
					}
				}
			}
		}
		.delivery-button{
			width: 100%;
			position: fixed;
			left: 0;
			bottom: 0;
			height:calc(env(safe-area-inset-bottom) + 120rpx);
			button{
				width: calc(100% - 64rpx);
				margin: 0 auto;
				height: 96rpx;
				border-radius: 200rpx;
				color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
				// background: linear-gradient(270deg, #D184CA 0%, #F0A492 100%);
				background: #47DFBD;
			}
		}
	}
</style>

